<?php
/**
 * Created by dutuwang.net
 * User: adophper <hello@adophper.com>
 * Date: 2018/4/9
 * Time: 17:07
 */
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;

$this->title = Yii::t('frontend', 'sponsor_in');
?>
<?=Html::jsFile('/static/common/js/ajaxfileupload.js')?>
<div class="scroll_box contBox ucenter_page">
    <!--主办方入驻-->
    <div class="register_are sponsor">
        <h2 class="register_are_title1">主办方入驻</h2>
        <div class="register_tips" style="<?=$model->status == 3 || $model->status == 2 ?:'display:none;'?>">
            <div class="clearfix">
                <span class="icon fl text-right"><i class="glyphicon glyphicon-exclamation-sign"></i></span>
                <div class="min fl">
                    <p>1. 公司信息须填项多，请确保信息的正确性后再提交。</p>
                    <p>2. 以下所需要上传电子版资质仅支持JPG、JPEG、PNG格式的图片，大小不超过1M；电子版为正本或副本扫描，如果复印件请加盖公章；法人是境外或港澳台地区，请提供护照扫描件或复印件。</p>
                </div>
            </div>
        </div>
        <div class="reg_log">
            <div class="f_relative reg_log_line">
                <hr />
                <span class="<?=$model->status == 0 ? 'sel' : ''?>"><em>1</em></span>
                <span class="<?=$model->status == 3 || $model->status == 2 ? 'sel' : ''?>"><em>2</em></span>
                <span class="<?=$model->status == 1 ? 'sel' : ''?>"><em>3</em></span>
            </div>
            <div class="f_relative reg_log_tip">
                <span class="<?=$model->status == 0 ? 'sel' : ''?>">公司信息认证</span>
                <span class="<?=$model->status == 3 || $model->status == 2 ? 'sel' : ''?>">资质审核</span>
                <span class="<?=$model->status == 1 ? 'sel' : ''?>">申请成功</span>
            </div>
        </div>
        <div class="form_box" style="<?=$model->status==0?:'display:none;'?>">
            <?php
            $form = ActiveForm::begin([
                'id' => 'company-form'
            ])
            ?>
            <div class="hidden">
                <?=$form->field($model, 'status')->hiddenInput(['class' => 'form_edit', 'value' => 3])->label(false)?>
            </div>
            <div class="tip_title">
                <p class="f_relative">公司基本信息<i class="t_yel">*</i></p>
            </div>
            <div class="register_are_list1">
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">公司名称:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9">
                                <?=$form->field($model, 'name')->textInput(['class' => 'form_edit'])->label(false)?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">公司电话:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9">
                                <?=$form->field($model, 'telphone')->textInput(['class' => 'form_edit'])->label(false)?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">指定联系人:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9">
                                <?=$form->field($model, 'contact_user')->textInput(['class' => 'form_edit'])->label(false)?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">指定手机号:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9">
                                <?=$form->field($model, 'contact_mobile')->textInput(['class' => 'form_edit'])->label(false)?>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item m_hight">
                    <label class="col-lg-2 col-md-2 col-sm-3">营业执照:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9 clearfix form-inline">
                        <?=$form->field($model, 'business')->radioList(array(
                            '普通营业执照' => '普通营业执照',
                            '企业三证合一' => '企业三证合一（自2015年10月1日起登记机关颁发的含统一信用代码的营业执照）',
                        ))->label(false)?>
                    </div>
                </div>
                <div class="register_are_item clearfix">
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <?=$form->field($model, 'business_photo')->hiddenInput(['class' => 'form_edit', 'id' => 'business_photo'])->label(false)?>
                        <div class="upload_litpic flex img">
                            <img id="business_image" src="<?=!empty($model->business_photo)?$model->business_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                            <div class="upload_del <?=!empty($model->business_photo)?:'hidden'?>"><i class="glyphicon glyphicon-remove"></i></div>
                        </div>
                        <div class="upload_img">
                            <span>上传营业执照</span>
                        </div>
                        <div class="hidden">
                            <input type="file" name="Filedata" class="file_upload_attach" id="business" data-id="attach">
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <?=$form->field($model, 'origanization_code_photo')->hiddenInput(['class' => 'form_edit', 'id' => 'origanization_code_photo'])->label(false)?>
                        <div class="upload_litpic flex img">
                            <img id="origanization_code_image" src="<?=!empty($model->origanization_code_photo)?$model->origanization_code_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                            <div class="upload_del <?=!empty($model->origanization_code_photo)?:'hidden'?>"><i class="glyphicon glyphicon-remove"></i></div>
                        </div>
                        <div class="upload_img">
                            <span>上传组织机构代码</span>
                        </div>
                        <div class="hidden">
                            <input type="file" name="Filedata" class="file_upload_attach" id="origanization_code" data-id="attach">
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <?=$form->field($model, 'certificate_photo')->hiddenInput(['class' => 'form_edit', 'id' => 'certificate_photo'])->label(false)?>
                        <div class="upload_litpic flex img">
                            <img id="certificate_image" src="<?=!empty($model->certificate_photo)?$model->certificate_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                            <div class="upload_del <?=!empty($model->certificate_photo)?:'hidden'?>"><i class="glyphicon glyphicon-remove"></i></div>
                        </div>
                        <div class="upload_img">
                            <span>上传税务登记证</span>
                        </div>
                        <div class="hidden">
                            <input type="file" name="Filedata" class="file_upload_attach" id="certificate" data-id="attach">
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <?=$form->field($model, 'opening_permit_photo')->hiddenInput(['class' => 'form_edit', 'id' => 'opening_permit_photo'])->label(false)?>
                        <div class="upload_litpic flex img">
                            <img id="opening_permit_image" src="<?=!empty($model->opening_permit_photo)?$model->opening_permit_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                            <div class="upload_del <?=!empty($model->opening_permit_photo)?:'hidden'?>"><i class="glyphicon glyphicon-remove"></i></div>
                        </div>
                        <div class="upload_img">
                            <span>上传开户许可证</span>
                        </div>
                        <div class="hidden">
                            <input type="file" name="Filedata" class="file_upload_attach" id="opening_permit" data-id="attach">
                        </div>
                    </div>
                </div>
            </div>
            <div class="min_register_btn flex f_center">
                <?=Html::submitButton("确认提交", ['class' => 'btn_red'])?>
            </div>
            <?php
            ActiveForm::end();
            ?>
        </div>
        <div class="form_box" style="<?=$model->status == 3 || $model->status == 2 ?:'display:none;'?>">
            <div class="tip_title">
                <p class="f_relative">公司基本信息<i class="t_yel">*</i></p>
            </div>
            <div class="register_are_list1">
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">公司名称:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->name?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">公司电话:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->telphone?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">指定联系人:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->contact_user?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">指定手机号:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->contact_mobile?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item m_hight">
                    <label class="col-lg-2 col-md-2 col-sm-3">营业执照:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->business?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix">
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <div class="upload_litpic flex img">
                            <img id="business_image" src="<?=!empty($model->business_photo)?$model->business_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <div class="upload_litpic flex img">
                            <img id="origanization_code_image" src="<?=!empty($model->origanization_code_photo)?$model->origanization_code_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <div class="upload_litpic flex img">
                            <img id="certificate_image" src="<?=!empty($model->certificate_photo)?$model->certificate_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <div class="upload_litpic flex img">
                            <img id="opening_permit_image" src="<?=!empty($model->opening_permit_photo)?$model->opening_permit_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                        </div>
                    </div>
                </div>
                <?php
                if ($model->status == 2) {
                ?>
                <div class="register_are_item clearfix gs_reg_item m_hight">
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <p>以上信息审核失败，失败原因：<?=$model->reason?></p>
                        <div class="clearfix">
                            <a href="<?=Yii::$app->urlManager->createUrl(['/member/zhubanfang', 'reset' => 1])?>">点击可重新填写信息提交申请</a>
                        </div>
                    </div>
                </div>
                <?php
                }
                ?>
            </div>
        </div>
        <div class="form_box" style="<?=$model->status == 1 ?:'display:none;'?>">
            <div class="tip_title">
                <p class="f_relative">公司基本信息<i class="t_yel">*</i></p>
            </div>
            <div class="register_are_list1">
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">公司名称:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->name?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">公司电话:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->telphone?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">指定联系人:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->contact_user?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item">
                    <label class="col-lg-2 col-md-2 col-sm-3">指定手机号:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->contact_mobile?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix gs_reg_item m_hight">
                    <label class="col-lg-2 col-md-2 col-sm-3">营业执照:</label>
                    <div class="col-lg-10 col-md-10 col-sm-9">
                        <div class="row clearfix">
                            <div class="col-lg-9 col-md-9 col-sm-9"><?=$model->business?></div>
                        </div>
                    </div>
                </div>
                <div class="register_are_item clearfix">
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <div class="upload_litpic flex img">
                            <img id="business_image" src="<?=!empty($model->business_photo)?$model->business_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <div class="upload_litpic flex img">
                            <img id="origanization_code_image" src="<?=!empty($model->origanization_code_photo)?$model->origanization_code_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <div class="upload_litpic flex img">
                            <img id="certificate_image" src="<?=!empty($model->certificate_photo)?$model->certificate_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-2 col-sm-3">
                        <div class="upload_litpic flex img">
                            <img id="opening_permit_image" src="<?=!empty($model->opening_permit_photo)?$model->opening_permit_photo:''?>" onerror="this.src='/static/frontend/image/nopic.png';" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".upload_img").on('click', function(e){
            console.log('0');
            $(this).next().find('.file_upload_attach').trigger('click');
        });
        //此处用了change事件，当选择好图片打开，关闭窗口时触发此事件
        $(".file_upload_attach").change(function (e) {
            var val = e.target.value;
            var point = val.lastIndexOf(".");
            var type = val.substr(point).toLowerCase();
            if (type != ".jpg" && type != ".jpeg" && type != ".png") {
                alert('系统目前只支持.jpg、.jpeg、.png文件格式');
                return false;
            }
            var file_id = $(this).attr('id');
            $.ajaxFileUpload({
                //处理图片的脚本路径
                url: '<?=\yii\helpers\Url::toRoute(['common/upload-thumb', 'event' => 1, 'dir' => 'user_company'])?>',
                type: 'post',       //提交的方式
                secureuri: false,   //是否启用安全提交
                fileElementId: file_id,     //file控件ID
                dataType: 'json',  //服务器返回的数据类型
                success: function (data, status) {  //提交成功后自动执行的处理函数
                    if (data.error) {
                        alert(data.msg);
                        return false;
                    } else {
                        $("#"+file_id+'_photo').val(data.fileUrl);
                        $("#"+file_id+'_image').attr('src', data.fileUrl);
                        $("#"+file_id+'_image').next().removeClass('hidden');
                    }
                },
                error: function (data, status, e) {   //提交失败自动执行的处理函数
                    alert(e);
                }
            })
        })

        //删除上传的图片
        $(".upload_del").on('click', function (e) {
            $(this).parent().prev().find('input').val('');
            $(this).prev('img').attr('src', '');
            $(this).addClass('hidden');
        })
    })
</script>
